export default {
	data(){
		return {
			step:0,
			step2:0,
			cidx: 0,
			weeks: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
			clandars: [],
			startDate:'',
			defaultDate:'',
			sdShow:false,
			cbItem:null,
			ppItem:null,
			
			adcGoItem:null,
			adcBackItem:null,
			ppGoItem:null,
			ppBackItem:null,
		}
	},
	watch:{
		step(newVal,oldVal){
			if(newVal==2) this.titleOne = '填写订单';
			else if(newVal<2) this.params.from+'-'+this.params.to;
			else this.titleOne = '支付成功';
		}
	},	
	methods:{
		initClandar(maxQueryDayNum) {
			for (let i = 0; i <= +maxQueryDayNum; i++) {
				this.clandars.push({
					tip: i == 0 ? '今天' : (i == 1 ? '明天' : (this.weeks[new Date(new Date().setDate(new Date()
						.getDate() + i)).getDay()])),
					date: new Date(new Date().setDate(new Date().getDate() + i)).Format('MM-dd'),
					day: new Date(new Date().setDate(new Date().getDate() + i)).Format('dd'),
					nyr: new Date(new Date().setDate(new Date().getDate() + i)).Format('yyyy-MM-dd')
				})
			}
			this.defaultDate = this.startDate;
			let fidx = this.clandars.findIndex(d => d.nyr == this.startDate);
			this.cidx = fidx == -1 ? '' : fidx;
		},
		changeDate(item, index) {
			this.cidx = index;
			this.startDate = this.clandars[index].nyr;
			this.defaultDate = this.startDate;
			this.params.startDate = this.startDate;
			
			this.getLineListOne(this.params);
		},
		sdConfirm(e){
			this.sdShow = false;
			this.startDate = new Date(e[0]).Format('yyyy-MM-dd');
			let fidx = this.clandars.findIndex(d => d.nyr == this.startDate);
			this.cidx = fidx == -1 ? '' : fidx;
		
			this.params.startDate = this.startDate;
			this.getLineListOne(this.params);
				
			if(this.cidx>-1){
				let that = this;
				const query = uni.createSelectorQuery();
				query.select('#svih_0').fields({size:true},res=>{
					that.scrollLeft = res.width*that.cidx||0;
				}).exec()
			}
		},
		toPassengerPay(item){
			this.step = 2;
			this.ppItem = item;
			this.$nextTick(()=>{
				this.$refs.cxghPassengerPay.init(item,null);
			})
		},
		toPayResult(item){
			this.step = 3;
			this.$nextTick(()=>{
				this.$refs.cxghPayResult.init(item);
			})
		},
		toPayResultTwo(item){
			this.step2 = 3;
			item.isCxghDc = true;
			this.$nextTick(()=>{
				this.$refs.cxghPayResultTwo.init(item);
			})
		},
		toCloseShip(){
			this.selectShowOne = false;
			this.selectShowTwo = false;
			this.step = 0;
			this.step2 = 0;
			this.cbItem = null;
			this.ppItem = null;
			this.adcGoItem = null;
			this.adcBackItem = null;
			this.ppGoItem = null;
			this.ppBackItem = null;
		},
		toReturnLast(){
			this.step--;
			this.$nextTick(()=>{
				if(this.step==1) this.$refs.cxghConfirmBooking.init(this.cbItem);
				else if(this.step==2) this.$refs.cxghPassengerPay.init(this.ppItem,null);
			})
		},
		toReturnLastTwo(){
			this.step2--;
			this.$nextTick(()=>{
				if(this.step2==1){
					let item = {
						goInfo:this.adcGoItem,
						backInfo:this.adcBackItem
					};
					this.$refs.cxghArriveDepartConfirm.init(item);
				}else if(this.step2==2) this.$refs.cxghPassengerPay.init(this.ppGoItem,this.ppBackItem);
			})
		},
		
		toPassengerPayTwo(item){
			this.step2 = 2;
			this.ppGoItem = item.goInfo;
			this.ppBackItem = item.backInfo;
			this.$nextTick(()=>{
				this.$refs.cxghPassengerPay.init(item.goInfo,item.backInfo);
			})
		}
	}
}